package br.com.devteam.base.util;

import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class MailUtil {
	
	private static final String SMTP_HOST = "smtp.gmail.com";
	private static final String SMTP_PORT = "587";
	private static final String ADM_PASSWORD = "de1ate1984";
	private static final String ADM_LOGIN = "edutav@gmail.com";
	private static final String ADM_FROM_MAIL = "edutav@gmail.com";
	private static final String ADM_FROM_NAME = "SGAP Sistema de Gerenciamento de Aplicações de Prova";

	public SimpleEmail mail = new SimpleEmail();

	public MailUtil() {
		try {
			mail.setFrom(ADM_FROM_MAIL, ADM_FROM_NAME);
		} catch (EmailException e) {
			e.printStackTrace();
		}
		mail.setStartTLSEnabled(true);
		mail.setHostName(SMTP_HOST);
		mail.setSmtpPort(Integer.valueOf(SMTP_PORT));
	}

	public MailUtil addDestinatario(String email, String nome) throws EmailException {
		mail.addTo(email, nome);
		return this;
	}

	public MailUtil setTituloMensagem(String tituloMensagem) {
		mail.setSubject(tituloMensagem);
		return this;
	}

	public MailUtil setMensagem(String mensagem) throws EmailException {
		mail.setMsg(mensagem);
		return this;
	}

	public void sendMail() throws EmailException, NoSuchAlgorithmException, KeyManagementException {		
		mail.setAuthentication(ADM_LOGIN, ADM_PASSWORD);
		mail.send();
	}


}
